<?php

// show off: template
require_once("configuration.php");
require_once("includes/io.php");
require_once("includes/template.php");
require_once("includes/category.php");
require_once("includes/product.php");
require_once("includes/function.php");
// 
$id = isset($_GET['id']) ? intval(sql_injection($_GET['id'])) : 0;
$page_id = isset($_GET['page']) ? intval(sql_injection($_GET['page'])) : 0;
if (is_int($id) && $id >= 0) {
    $category_id = $id;

    $title = "Home";
    $template = new template("default");

// variable initializationu
    $categories = "";
    $product_rows = "";
    $menu_rows = "";

    // required settings
    require_once ("includes/setting.php");
    $setting = new setting();
// PRODUCT SECTION
    $news = new Product();
    $news->category_id = $id;
    $news->limit = $setting->product_limit;
    $total_products = $news->get_total_products_category();
// required pagination
    require_once ("includes/pagination.php");
    $pagination = new pagination("index.php?page=", $page_id, $total_products, $news->limit);
// set the start to get products    
    $news->start = $pagination->start;
    $query_products = $news->get_news();
    $pagination_html = $pagination->get_html();

    if ($mysql->n($query_products) > 0) {
        while ($obj = $mysql->fo($query_products)) {
            $news = Product::static_set_object($obj);

            eval("\$product_rows .= \"" . $template->get("news.rows") . "\";");
        }
    } else {
        eval("\$product_rows = \"" . $template->get("product.empty") . "\";");
    }

    eval("\$products = \"" . $template->get("index.product") . "\";");

// Categories section    

    require_once("includes/list.categories.php");
// cart
    require_once("includes/function.number.php");
    require_once("includes/cart.php");
    require_once("includes/list.cart.php");

// Navigator
    require_once("includes/page.php");
    require_once("includes/list.menu.php");

// layout
    //AG: change content to category content
    eval("\$content = \"" . $template->get("category.content") . "\";");

    eval("\$header = \"" . $template->get("header") . "\";");
    eval("\$cart = \"" . $template->get("body.cart") . "\";");
    eval("\$body = \"" . $template->get("body") . "\";");
    eval("\$footer = \"" . $template->get("footer") . "\";");
    eval("\$index = \"" . $template->get("index") . "\";");

// display all
    echo ($index); // can use echo $template->compress($index) to compress size of html

    require_once("configuration.end.php");
}
?>